package de.farbstreich.tozen2.client;

import java.util.HashMap;

public class GameData {

	int playerId;
	String name;
	
	public GameData() {
		
	}
	
	public HashMap<Integer, Player> players = new HashMap<Integer, Player>();
	public HashMap<Integer, GameType> gameTypes = new HashMap<Integer, GameType>();
	
	public MyGame myGame = new MyGame();
	
	public class MyGame {
		/**
		 * @deprecated
		 */
		boolean isAdmin = false;
		int gameId;
		String gameName;
		String gameTitle;
		
		HashMap<Integer,Player> colors = new HashMap<Integer, Player>();
		HashMap<Integer,Player> players = new HashMap<Integer, Player>();
		/**
		 * @deprecated
		 */
		public TokenPosition[][] gameBoard = new TokenPosition[12][12];
		
		/**
		 * @deprecated
		 * @param x
		 * @param y
		 * @param playerId
		 * @param tokenType
		 * @param color
		 */
		public void setTokenPosition(int x, int y, int playerId, int tokenType, int color) {
			gameBoard[x][y] = new TokenPosition(playerId, tokenType, color);
		}
		/**
		 * @deprecated
		 * @param status
		 */
		public void setAdmin(boolean status) {
			this.isAdmin = status;
		}
		/**
		 * @deprecated
		 * @param x
		 * @param y
		 * @return
		 */
		public TokenPosition getTokenPosition(int x, int y) {
			return gameBoard[x][y];
		}
	}
	
	public class Game {
		int gameId;
		String gameName;
		String gameType;
		int maxPlayersCount;
		int minPlayersCount;
		public Game() {}
		public Game(int id, String name, int max, int min) {
			this.gameId = id;
			this.gameName = name;
			this.maxPlayersCount = max;
			this.minPlayersCount = min;
		}
		
		public Game(int id, String name) {
			this.gameId = id;
			this.gameName = name;
			this.maxPlayersCount = 4;
			this.minPlayersCount = 2;
		}
		
		public String toString() {
			return this.gameName;
		}
	}
	
	public class GameType {
		int gameTypeId;
		String gameTypeTitle;
		
		public GameType(int id, String name) {
			this.gameTypeId = id;
			this.gameTypeTitle = name;
		}
		
		public String toString() {
			return this.gameTypeTitle;
		}
	}
	
	
	/**
	 * @deprecated	
	 * @author mo
	 *
	 */
	public class TokenPosition {
		public  int playerId;
		public  int tokenType;
		public  int color;
		public	boolean isSet = false;
		
		public TokenPosition(){}
		
		public TokenPosition(int id, int type, int color) {
			this.playerId = id;
			this.tokenType = type;
			this.color = color;
			this.isSet = true;
		}
	}
	
	public class Player {
		public int playerId;
		public String name;
		public int color;
		public int panelId;
		
		public Player() {}
		public Player(int id, String name, int color){
			this.playerId = id;
			this.name = name;
			this.color = color;
		}
		public Player(int id, String name){
			this.playerId = id;
			this.name = name;
			this.color = 0;
		}
		
		public String toString() {
			return name;
		}
	}
	
	public void addLocalPlayer(int playerId, String username) {
		this.playerId = playerId;
		this.name = username;
	}
	
	public void addPlayer(int playerId, String username, int color) {
		Player newPlayer = new Player();
		newPlayer.playerId = playerId;
		newPlayer.name = username;
		newPlayer.color = color;
		try {
			players.put(playerId, newPlayer);
		} catch (Exception e) {
			System.out.println("Fehler beim Spieler einfügen: " + e);
		}
	}

	public void removePlayer(int playerId) {
		players.remove(playerId);
	}
	
	public Player getPlayerById(int playerId) {
		return players.get(playerId);
	}
	
	/*public String[] getPlayersAsString() {
		Iterator it = players.keySet().iterator();
		while(it.hasNext()) {
			players.get(it.next()).name;
		}
		return null;
		
	}*/
	
}
